package com.demo.annotation.processor;

import com.demo.annotation.annotation.MyCustomAnnotation;
import com.demo.annotation.domain.Demo02;
import com.demo.annotation.domain.MyClass;

import java.lang.reflect.Method;

public class AnnotationProcessor {
    public static void processAnnotations(Class<?> clazz) {
        // 检查类是否带有 MyCustomAnnotation 注解
        if (clazz.isAnnotationPresent(MyCustomAnnotation.class)) {
            MyCustomAnnotation annotation = clazz.getAnnotation(MyCustomAnnotation.class);
            System.out.println("Author: " + annotation.author());
            System.out.println("Version: " + annotation.version());
        }

        // 遍历类的所有方法并检查是否有 MyCustomAnnotation 注解
        for (Method method : clazz.getDeclaredMethods()) {
            if (method.isAnnotationPresent(MyCustomAnnotation.class)) {
                MyCustomAnnotation annotation = method.getAnnotation(MyCustomAnnotation.class);
                System.out.println("Method " + method.getName() + " has Author: " + annotation.author());
            }
        }
    }

    public static void main(String[] args) {
        processAnnotations(Demo02.class);
        processAnnotations(MyClass.class);// 假设 MyClass 已经被 MyCustomAnnotation 注解
    }
}
